package infopreserve.main.mobile;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
 
public class UploadListView extends BaseAdapter {
 
    private Activity activity;
    private ArrayList<Item> data;
    private static LayoutInflater inflater=null;
    private Item i;
    private UploadFile p;
 
    public UploadListView(Activity a, ArrayList<Item> uploadList) {
    	data = uploadList;
        activity = a;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        p = (UploadFile)a;
    }
 
    public Object getItem(int position) {
        return position;
    }
 
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(final int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        i = new Item();
        i = data.get(position);
        if(convertView==null)
            vi = inflater.inflate(R.layout.uploaditem, null);
 
        TextView name = (TextView)vi.findViewById(R.id.textView1);
        TextView size = (TextView)vi.findViewById(R.id.textView2);
        ImageButton b = (ImageButton)vi.findViewById(R.id.remove);
        TextView loc = (TextView)vi.findViewById(R.id.loc);
        b.setOnClickListener(new Button.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        i.remove();
                        p.updateList();
                    }
                }
            );
        // Setting all values in listview
        name.setText(i.getName());
        size.setText(i.getSize() + " ");
        loc.setText(i.getLoc() + " ");
        
        return vi;
    }

	@Override
	public int getCount() {
		return data.size();
	}
}
